package org.theqcp.wow.model.mechanics;

public enum Slot {

	//ragdoll
	HEAD(0,"Head"),
	NECKLACE(1,"Necklace"),
	SHOULDER(2,"Shoulder"),
	SHIRT(3,"Shirt"),
	CHEST(4,"Chest"),
	BELT(5,"Belt"),
	PANTS(6,"Pants"),
	FEET(7,"Feet"),
	BRACER(8,"Bracer"),
	HANDS(9,"Hands"),
	RING1(10, "Ring 1", new Slot[]{Slot.RING2}),
	RING2(11, "Ring 2", new Slot[]{Slot.RING1}),
	TRINKET1(12, "Trinket 1", new Slot[]{Slot.TRINKET2}),
	TRINKET2(13, "Trinket 2", new Slot[]{Slot.TRINKET1}),
	BACK(14, "Back"),
	MAINHAND(15, "Main Hand"),
	OFFHAND(16, "Off Hand"),
	RANGED_RELIC(17, "Ranged / Relic"),
	TABARD(18, "Tabard"),
	
	//handedness
	ONEHAND(19,"One Hand", new Slot[]{Slot.MAINHAND,Slot.OFFHAND}),
	TWOHAND(20,"Two Hand", new Slot[]{}, new Slot[]{Slot.OFFHAND}, Slot.MAINHAND),
	
	//wildcards
	NONE(99, "None"),
	ANY(-1, "Any"),
		
	;
	
	private int index;
	private String name;
	private Slot base;
	
	/**
	 * Slots that can do the same thing or hold the same type of item 
	 */
	private Slot[] companionSlots;
	
	/**
	 * Also requires the use of the other slots in the list 
	 */
	private Slot[] requiresSlots;
	
	private Slot(int slotNumber, String slotName) {
		this.index = slotNumber;
		this.name = slotName;
		
		//make as empty lists
		this.companionSlots = new Slot[]{};
		this.requiresSlots = new Slot[]{};
		
		//self is base slot, so set null
		this.base = null;
	}
	
	private Slot(int slotNumber, String slotName, Slot[] companion) {
		//call upper constructor
		this(slotNumber,slotName);
	
		//set companion slots
		this.companionSlots = companion;
		
		//hack for ONEHAND!
		if(this.companionSlots.length > 1) {
			this.base = this.companionSlots[0];
		} else {
			this.base = null;
		}
	}
	
	private Slot(int slotNumber, String slotName, Slot[] companion, Slot[] requires, Slot base) {
		//call upper constructor
		this(slotNumber,slotName,companion);
		
		//set required slots
		this.requiresSlots = requires;
		
		//set base slot manually
		this.base = base;
	}

	public int getIndex() {
		return this.index;
	}
	
	public String getSlotName() {
		return this.name;
	}
	
	public Slot[] getCompanionSlots() {
		return this.companionSlots;
	}
	
	public Slot[] getRequiresAlso() {
		return this.requiresSlots;
	}
	
	public Slot getBaseSlot() {
		Slot b = this.base;
		if(b == null || b.equals(null)) {
			b = this;
		}
		return b;
	}
	
	public String toString() {
		return String.format("%s - %s", String.valueOf(this.index),this.name);
	}
	
	/**
	 * Get the slot enum by slot index
	 * 
	 * @param index
	 */
	public static Slot getSlotByIndex(int index) {
		
		//return name
		for(Slot s : Slot.values()) {
			if(s.getIndex() == index) {
				return s;
			}
		}
		
		//return human as default
		return Slot.HEAD;
		
	}
}
